<?php
/*
 * class.cbd.php
 * 商家商圈
 * @version 0.1
 * @author samuel
 * @date 2009-05-12
 */
include_once 'class.sellerBase.php';
class seller_cbd extends sellerBase {
    private $step;
    private $classname;
    private $tpl_file;

    function  __construct($core) {
        parent::__construct();

        //参数处理
        $this->step = $this->params['step'];
        if(!$this->step) $this->step = "list";
        $this->classname = strtolower(trim(get_class($this)));
        $this->tpl_file = $this->classname . "_" . $this->step . ".html";

        $this->run();
    }

    function run(){
        var_dump($this->step);
        switch($this->step){
            case 'list':
                $page = is_numeric($this->params['page']) ? $this->params['page'] : 1;
                $pagesize = 20;
                $current_url = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING'];
                $arr_limit = array('page'=>$page, 'pagesize'=>$pagesize, 'url'=>$current_url);
                $arr_cbds_info = $this->getSellerCBDList("", array("SellerCBDID"=>"desc"), $arr_limit);
                $arr_cbds = $arr_cbds_info['list'];
                $pager = $arr_cbds_info['pager'];
                $this->core->tpl->assign('arr_cbds', $arr_cbds);
                $this->core->tpl->assign('pager', $pager);
                break;
            case 'add':
                $cities = $this->getSellerAllCityList();
				$this->core->tpl->assign('cities', $cities);
                break;
            case 'do_add':
                $city_id= $this->params['SellerCityID'];
                $cbd_name = $this->params['SellerCBDNameCN'];
                $tag = $this->addNewCBD($city_id, $cbd_name);
                if(!$tag){
                    $this->core->utility->messagePrompt($this->error);
                }
                $this->core->utility->messagePrompt('添加成功!');
                return;
                break;
            case 'edit':
				$cities = $this->getSellerAllCityList();
				$this->core->tpl->assign('cities', $cities);
                $cid = $this->params['cid'];
                $cbd = $this->getSellerCBDInfo($cid);
				$this->core->tpl->assign('cbd', $cbd);
                break;
			case 'do_edit':
				$cid = $this->params['cid'];
				$cbd_info['SellerCityID'] = $this->params['SellerCityID'];
				$cbd_info['SellerCBDNameCN'] = $this->params['SellerCBDNameCN'];
				$this->updateInfo('fun_seller_cbd', 'SellerCBDID', $cid, $cbd_info);
				if($this->error){
					$this->core->utility->messagePrompt($this->error);
				}else{
					$this->core->utility->messagePrompt('更新成功！');
				}
				return;
				break;
			case 'del':
				$cid = $this->params['cid'];
				$this->delInfo('fun_seller_cbd', 'SellerCBDID', $cid);
				if($this->error){
					$this->core->utility->messagePrompt($this->error);
				}else{
					$this->core->utility->messagePrompt('删除成功！');
				}
				return;
				break;
			case 'batch_del':
                $ids = $this->params['checkboxes'];
                if(is_array($ids)){
                    foreach($ids as $id){
                        $this->delInfo('fun_seller_cbd', 'SellerCBDID', $id);
                    }
                }
                if($this->error){
					$this->core->utility->messagePrompt($this->error);
				}else{
					$this->core->utility->messagePrompt('删除成功！');
				}
                return;
                break;
			case 'search':
				$search_cityname = $this->params['search_cityname'];
				$search_cbdname = $this->params['search_cbdname'];
				$search_url_append = "&step=".$this->step."&search_cityname=".$search_cityname."&search_cbdname=".$search_cbdname;
				$arr_filter = array();
				if($search_cityname){
					$arr_filter[] = array('attr'=>'SellerCityNameCN', 'value'=>$search_cityname, 'match'=>'like', 'join'=>'b');
				}
				if($search_cbdname){
					$arr_filter[] = array('attr'=>'SellerCBDNameCN', 'value'=>$search_cbdname, 'match'=>'like');
				}
				$page = is_numeric($this->params['page']) ? $this->params['page'] : 1;
                $pagesize = 20;
                $current_url = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING'] . $search_url_append;
                $arr_limit = array('page'=>$page, 'pagesize'=>$pagesize, 'url'=>$current_url);
                $arr_cbds_info = $this->getSellerCBDList($arr_filter, array("SellerCBDID"=>"desc"), $arr_limit);
                $arr_cbds = $arr_cbds_info['list'];
                $pager = $arr_cbds_info['pager'];
                $this->core->tpl->assign('arr_cbds', $arr_cbds);
                $this->core->tpl->assign('pager', $pager);
				//共用一个模板
				$this->tpl_file = "seller_cbd_list.html";
				break;
        }
        $this->core->tpl->display($this->tpl_file);
    }
}
?>
